/**
 * <pre>
 * Copyright 2008 openmaximo.net
 * 
 * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an &quot;AS IS&quot; BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 * </pre>
 */
package net.openmaximo.maximo.app.excelconfig;

import java.rmi.RemoteException;

import net.openmaximo.log.Log4jLogger;

import psdi.app.configure.FldSetViewChangedMAXTable;
import psdi.mbo.MboValue;
import psdi.util.MXException;

/**
 * @author openmaximo.net
 * 
 */
public class FldObjectname extends FldSetViewChangedMAXTable {
  private static final Class iClass = ExcelConfig.class;

  /**
   * @param mbv
   * @throws MXException
   */
  public FldObjectname(MboValue mbv) throws MXException {
    super(mbv);
    setRelationship("MAXOBJECTCFG",
        "objectname = :objectname and changed != 'R' ");
  }

  /**
   * <h3>ATTRIBUTENAME readonly</h3>
   * <p>
   * If the <i>OBJECTNAME</i> is empty the <i>ATTRIBUTENAME</i> will be set to
   * <i>readonly</i>.
   * </p>
   * 
   * @see psdi.app.configure.FldSetViewChangedMAXTable#action()
   */
  public void action() throws MXException, RemoteException {
    Log4jLogger.info(iClass, ".action() started...");
    super.action();
    // If the <i>OBJECTNAME</i> is empty the <i>ATTRIBUTENAME</i> will be set to
    // <i>readonly</i>.
    MboValue thisMboVal = this.getMboValue();
    MboValue attributenameMboVal = this.getMboValue("attributename");
    if ((thisMboVal != null) && (attributenameMboVal != null)) {
      if (thisMboVal.isNull()) {
        attributenameMboVal.setReadOnly(true);
      } else {
        attributenameMboVal.setReadOnly(false);
      }
    }
    Log4jLogger.info(iClass, ".action() finished.");
  }

}
